//
//  CooperateDetailController.m
//  i5db
//
//  Created by iMuse on 15-5-11.
//  Copyright (c) 2015年 mySelf. All rights reserved.
//

#import "CooperateDetailController.h"
#import "SmallView.h"
#import "AppCenter.h"
#import "SendMessageView.h"

@interface CooperateDetailController ()
{
    UIScrollView * scrollView;
    UIView       * contentView;
    
    UILabel      * companyLabel;
    UIView       * headView;
    
    UILabel      * xuqiuContent;
    UILabel      * ziyuanContent;
    
    UIButton     * messageButton;
    

   
}
@end

@implementation CooperateDetailController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"合作信息";
    }
    return self;
}
-(void)updateViewConstraints
{
    [super updateViewConstraints];
    
    [messageButton autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:70];
    [messageButton autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:20];
    [messageButton autoSetDimensionsToSize:CGSizeMake(40, 40)];
    
    
    [scrollView autoPinToTopLayoutGuideOfViewController :self withInset:0];
    [scrollView autoPinToBottomLayoutGuideOfViewController:self withInset:0];
    [scrollView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:0];
    [scrollView autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:0];
    
    [contentView autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:scrollView withOffset:-64];
    [contentView autoPinEdge:ALEdgeLeft toEdge:ALEdgeLeft ofView:scrollView withOffset:0];
    [contentView autoPinEdge:ALEdgeRight toEdge:ALEdgeRight ofView:scrollView withOffset:0];
    [contentView autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:scrollView withOffset:0];
    [contentView autoSetDimension:ALDimensionWidth toSize:SCREEN_WIDTH];
    
    
    [headView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:0];
    [headView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:0];
    [headView autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:0];
    [headView autoSetDimension:ALDimensionHeight toSize:90];
    
    [companyLabel autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:10];
    [companyLabel autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:10];
    
    

}
-(void) initNavigationBar{
    [super initNavigationBar];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view setNeedsUpdateConstraints];
    [self initNavigationBar];
    [self initView];
    
   
}
-(void) initView
{
   
    
    scrollView = [UIScrollView newAutoLayoutView];
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:scrollView];
    
    contentView  = [UIView newAutoLayoutView];
    contentView.backgroundColor = [UIColor whiteColor];
    [scrollView addSubview:contentView];
    
    headView = [UIView newAutoLayoutView];
   
    [contentView addSubview:headView];
    
    messageButton = [UIButton newAutoLayoutView];
    /*[messageButton setTitle:@"给ta留言" forState:UIControlStateNormal];
    messageButton.titleLabel.font = [UIFont systemFontOfSize:8];
    [messageButton setTitleColor:[AppCenter color:@"76,187,248,1"] forState:UIControlStateNormal];*/
    [messageButton addTarget:self action:@selector(messageButton:) forControlEvents:UIControlEventTouchUpInside];
    [messageButton setBackgroundImage:[UIImage imageNamed:@"third_normal"] forState:UIControlStateNormal];
    [self.view addSubview:messageButton];
    
    UILabel* label = [UILabel newAutoLayoutView];
    label.backgroundColor = [AppCenter color:@"225,225,225,1"];
    [headView addSubview:label];
    [label autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:10];
    [label autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:10];
    [label autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:0];
    [label autoSetDimension:ALDimensionHeight toSize:1];
    
    companyLabel = [UILabel newAutoLayoutView];
    companyLabel.text = @"慧聪-电子汽车网";
    companyLabel.font = [UIFont systemFontOfSize:13];
    [headView addSubview:companyLabel];
    
    SmallView * locaView = [SmallView newAutoLayoutView];
    [locaView settingAttrView:[UIImage imageNamed:@"fujin.png"] text:@"全国" color:[AppCenter color:@"76,187,248,1"]];
    [headView addSubview:locaView];
    [locaView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:10];
    [locaView autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:10];
    [locaView autoSetDimensionsToSize:CGSizeMake(40, 12)];
    
    
    SmallView * hoteView = [SmallView newAutoLayoutView];
    [hoteView settingAttrView:[UIImage imageNamed:@"vipBizIcon102_1.png"] text:@"90" color:[UIColor redColor]];
    [headView addSubview:hoteView];
    [hoteView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:locaView withOffset:5];
    [hoteView autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:10];
    [hoteView autoSetDimensionsToSize:CGSizeMake(40, 12)];
    
    SmallView * timeView = [SmallView newAutoLayoutView];
    [timeView settingAttrView:[UIImage imageNamed:@"mqz_ugc_btn_time.png"] text:@"2014/12/23" color:[AppCenter color:@"126,126,126,1"]];
    [headView addSubview:timeView];
    [timeView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:companyLabel withOffset:5];
    [timeView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:10];
    [timeView autoSetDimensionsToSize:CGSizeMake(40, 12)];
    
    
    UIButton  * messageBtn = [UIButton newAutoLayoutView];
    [messageBtn setTitle:@"联系方式" forState:UIControlStateNormal];
    messageBtn.titleLabel.font = [UIFont boldSystemFontOfSize:10];
    messageBtn.layer.cornerRadius = 3;
    [messageBtn setTitleColor:[AppCenter color:@"76,187,248,1"] forState:UIControlStateNormal];
    messageBtn.layer.borderWidth = 0.5;
    messageBtn.layer.borderColor = [AppCenter color:@"76,187,248,1"].CGColor;
    [headView addSubview:messageBtn];
    [messageBtn autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:10];
    [messageBtn autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:timeView withOffset:10];
    [messageBtn autoSetDimensionsToSize:CGSizeMake(60, 25)];
    
    UILabel * xuqiu = [UILabel newAutoLayoutView];
    xuqiu.text      = @"需求";
    xuqiu.font      = [UIFont boldSystemFontOfSize:15];
    [contentView addSubview:xuqiu];
    [xuqiu autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:10];
    [xuqiu autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:headView withOffset:10];
    
    xuqiuContent = [UILabel newAutoLayoutView];
    xuqiuContent.text = @"寻求汽车相关网站广告位，友链，嵌入等方式来换取流量，引入页面:http://wwww.hulebaji.com寻求汽车相关网站广告位，友链，嵌入等方式来换取流量，引入页面:http://wwww.hulebaji.com";
    xuqiuContent.textColor = [AppCenter color:@"126,126,126,1"];
    xuqiuContent.numberOfLines = 0;
    xuqiuContent.font = [UIFont systemFontOfSize:12];
    [contentView addSubview:xuqiuContent];
    
    [xuqiuContent autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:xuqiu withOffset:5];
    [xuqiuContent autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:10];
    [xuqiuContent autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:10];
    
    UILabel * ziyuan = [UILabel newAutoLayoutView];
    ziyuan.text = @"资源";
    ziyuan.font = xuqiu.font;
    [contentView addSubview:ziyuan];
    [ziyuan autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:xuqiuContent withOffset:10];
    [ziyuan autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:10];
    
    ziyuanContent = [UILabel newAutoLayoutView];
    ziyuanContent.text = @"日均点击500IP广告位，pre权重7的首页友链资源日均点击500IP广告位，pre权重7的首页友链资源日均点击500IP广告位，pre权重7的首页友链资源日均点击500IP广告位，pre权重7的首页友链资源日均点击500IP广告位，pre权重7的首页友链资源";
    ziyuanContent.font = xuqiuContent.font;
    ziyuanContent.textColor = xuqiuContent.textColor;
    ziyuanContent.numberOfLines = 0;
    [contentView addSubview:ziyuanContent];
    [ziyuanContent autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:ziyuan withOffset:5];
    [ziyuanContent autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:10];
    [ziyuanContent autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:10];
    
    
  CGSize xuqiuSize =   [AppCenter sizeWithString:xuqiuContent.text font:xuqiuContent.font maxHeight:1000 maxWeight:SCREEN_WIDTH];
    
  CGSize ziyuanSize =  [AppCenter sizeWithString:ziyuanContent.text font:ziyuanContent.font maxHeight:1000 maxWeight:SCREEN_WIDTH];
    
    CGFloat height = xuqiuSize.height+ziyuanSize.height+30+90;
    
    if (height<SCREEN_HEIGHT) {
        height = SCREEN_HEIGHT-64;
    }
    [contentView autoSetDimension:ALDimensionHeight toSize:height];
    
    
}

-(void)messageButton:(UIButton*) button
{
    [SendMessageView sendMessage];
}

- (void)viewWillAppear:(BOOL)animated {
    
    
    [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
    [super viewWillAppear:animated];
    
    
}


- (void)viewWillDisappear:(BOOL)animated {
    
    [[self rdv_tabBarController] setTabBarHidden:NO animated:YES];
    
    [super viewWillDisappear:animated];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    
}



@end
